/**
 * PHOSIDE: PHosphorylation Site IDentification Engine.
 * Copyright 2009 Digital Biology Lab, University of Missouri.
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version. <p/> This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more
 * details.
 */

package phoside.ui.task;

import java.util.Properties;
import java.util.Set;

import phoside.PhosideTrain;
import phoside.PhosphoProteins;
import phoside.PhosphoProteins.PhosphoType;
import phoside.model.PhosideModel;

/**
 *
 */
public class PhosideTrainTask extends AbstractTask {
    private final PhosphoProteins phosphoData;
    private final Properties props;
    private final Set<PhosphoType> types;

    private final PhosideTrain trainer;

    public PhosideTrainTask(final PhosphoProteins phosphoData,
                            final Set<PhosphoType> types,
                            final Properties props) {
            super("Model training");
            this.phosphoData = phosphoData;
            this.props = props;
            this.types = types;
            trainer = new PhosideTrain();
    }

    /**
     * Executes Task.
     */
    //@Override
    public void run() {
            try {
                    taskMonitor.setPercentCompleted(-1);
                    trainer.setTaskMonitor(taskMonitor);
                    
                    taskMonitor.setStatus("The model is being trained...");
                    obj = trainer.train(phosphoData, types, props);

                    taskMonitor.setPercentCompleted(100);
                    taskMonitor.setStatus("The model has been successfully trained.");

                    success = true;
            } catch (Exception e) {
                    taskMonitor.setPercentCompleted(100);
                    taskMonitor.setStatus("Failed to train model.\n"+e.getMessage());
                    e.printStackTrace();
                    return;
            }
    }

    public PhosideModel getModel() {
        return (PhosideModel)obj;
    }

}
